
package com.dps.omc.action;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dps.omc.service.IJobArtifactService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dps.common.domain.view.BizData4Page;
import com.dps.omc.model.JobArtifact;
import com.dps.common.utils.IdGenerator;
import com.dps.common.utils.JsonResult;
import com.dps.common.utils.PageParam;
import com.dps.common.utils.Constants;

@Controller
public class JobArtifactAction extends AbstractAdminController<IJobArtifactService>{

    @Autowired
    private IJobArtifactService jobArtifactService;
    
    @RequestMapping(value="/jobartifact/list")
    public String list(JobArtifact jobArtifact,ModelMap model,PageParam pageParam,HttpServletRequest request,HttpServletResponse response){

        //获取参数
    	Map<String, Object> conditions = getQueryMap(jobArtifact); 	
    	BizData4Page<JobArtifact> pageCtx = doPage(model, conditions, pageParam);
    	model.addAttribute("jobArtifact", jobArtifact);
    	return "/module/jobartifact/list";
    }    
    
    @RequestMapping(value="/jobartifact/add")
    public String add(ModelMap model,HttpServletRequest request,HttpServletResponse response){

    	model.addAttribute("jobArtifact", new JobArtifact());
        return "module/jobartifact/edit";
    }    
    
    @RequestMapping(value="/jobartifact/edit")
    public String edit(String id,ModelMap model,HttpServletRequest request,HttpServletResponse response){
    	
    	JobArtifact jobArtifact = jobArtifactService.fetch(id);
    	model.addAttribute("jobArtifact", jobArtifact);
        return "module/jobartifact/edit";
    }    
    
    @RequestMapping(value="/jobartifact/save")
    @ResponseBody
    public String save(HttpServletRequest request,JobArtifact jobArtifact){
		boolean isAddNew = StringUtils.isBlank(jobArtifact.getId())?true:false;
		if(isAddNew)
		{
			jobArtifact.setId(IdGenerator.createNewId());
			jobArtifactService.add(jobArtifact);
		}
		else
		{
			jobArtifactService.update(jobArtifact);
		}
        return JsonResult.saveSuccessClose(Constants.MAIN_TAB).toString();
    }    
    
    @RequestMapping(value="/jobartifact/delete")
    @ResponseBody
    public String delete(String ids,HttpServletRequest request){
    	
    	jobArtifactService.deleteByIds(ids);
    	return JsonResult.DELETE_SUCCESS.toString();
    }       
	
    protected Map getQueryMap(JobArtifact jobArtifact)
    {
    	Map<String, Object> conditions = new HashMap();

        conditions.put("artifactId", jobArtifact.getArtifactId());
        conditions.put("artifactPath", jobArtifact.getArtifactPath());
        conditions.put("artifactName", jobArtifact.getArtifactName());
        conditions.put("artifactSize", jobArtifact.getArtifactSize());
        conditions.put("bizType", jobArtifact.getBizType());
        conditions.put("jobId", jobArtifact.getJobId());
        conditions.put("templateId", jobArtifact.getTemplateId());
        conditions.put("groupType", jobArtifact.getGroupType());
        conditions.put("createDate", jobArtifact.getCreateDate());
        conditions.put("createrId", jobArtifact.getCreaterId());
        conditions.put("createrName", jobArtifact.getCreaterName());
        return conditions;
    }

    @Override
    protected IJobArtifactService getMainService() {
        return jobArtifactService;
    }

    @Override
    protected String getMainObjName() {
        return "jobartifact";
    }

    @Override
    protected String getViewTitle() {
        return "jobartifact";
    }
}
